// Created from GroupGenerationTemplate
// For Decisions HL7 Engine
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using DecisionsFramework.Design.Properties;
using Decisions.HL7.DataTypes;
using ST = System.String;
using SI = System.String;
using IS = System.String;
using ID = System.String;
using SNM = System.String;

namespace Decisions.HL7.Message
{
    [DataContract]
	public class COMMON_ORDER_RSP_Z82 : AbstractGroup
    {
        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("32 ORC",32)]
  	    [HL7Field(HL7Version.v24, 32, HL7Repeat.False, HL7Required.True,"ORC")]
	    public ORC ORC {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("33 ORDER_DETAIL",33)]
  	    [HL7Field(HL7Version.v24, 33, HL7Repeat.False, HL7Required.False,"ORDER_DETAIL_RSP_Z82")]
	    public ORDER_DETAIL_RSP_Z82 ORDER_DETAIL {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("54 ENCODED_ORDER",54)]
  	    [HL7Field(HL7Version.v24, 54, HL7Repeat.False, HL7Required.False,"ENCODED_ORDER_RSP_Z82")]
	    public ENCODED_ORDER_RSP_Z82 ENCODED_ORDER {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("65 RXD",65)]
  	    [HL7Field(HL7Version.v24, 65, HL7Repeat.False, HL7Required.True,"RXD")]
	    public RXD RXD {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("67 RXR",67)]
  	    [HL7Field(HL7Version.v24, 67, HL7Repeat.True, HL7Required.True,"RXR")]
	    public RXR[] RXR {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("71 RXC",71)]
  	    [HL7Field(HL7Version.v24, 71, HL7Repeat.True, HL7Required.False,"RXC")]
	    public RXC[] RXC {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("74 OBSERVATION",74)]
  	    [HL7Field(HL7Version.v24, 74, HL7Repeat.True, HL7Required.True,"OBSERVATION_RSP_Z82")]
	    public OBSERVATION_RSP_Z82[] OBSERVATION {get;set;}



		#region Parser Helpers and Conrete Impls

        internal override void ConsumeTextSegmentsForGroup(Stack<string> availableData, HL7ParserOptions options) {

			ORC = PopSegmentParseAndCheckRequired<ORC>(availableData, options, "ORC");
			ORDER_DETAIL = ProcessGroup<ORDER_DETAIL_RSP_Z82>(availableData, options, "ORDER_DETAIL");
			ENCODED_ORDER = ProcessGroup<ENCODED_ORDER_RSP_Z82>(availableData, options, "ENCODED_ORDER");
			RXD = PopSegmentParseAndCheckRequired<RXD>(availableData, options, "RXD");
			RXR = PopSegmentParseAndCheckRequiredArray<RXR>(availableData, options, "RXR");
			RXC = PopSegmentParseAndCheckRequiredArray<RXC>(availableData, options, "RXC");
			OBSERVATION = ProcessGroupArray<OBSERVATION_RSP_Z82>(availableData, options, "OBSERVATION");
        }

		internal override bool CanConsume(string availableData, HL7ParserOptions options)
        {
			bool isORC = availableData.StartsWith("ORC", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("ORC", options.Version) || isORC) {
				return isORC;
			}
			ORDER_DETAIL_RSP_Z82 testORDER_DETAIL_RSP_Z82 = new ORDER_DETAIL_RSP_Z82();
			bool grpCCORDER_DETAIL_RSP_Z82 = (testORDER_DETAIL_RSP_Z82.CanConsume(availableData, options));
			if (IsRequired("ORDER_DETAIL", options.Version) || grpCCORDER_DETAIL_RSP_Z82) {
				return grpCCORDER_DETAIL_RSP_Z82;
			}
			ENCODED_ORDER_RSP_Z82 testENCODED_ORDER_RSP_Z82 = new ENCODED_ORDER_RSP_Z82();
			bool grpCCENCODED_ORDER_RSP_Z82 = (testENCODED_ORDER_RSP_Z82.CanConsume(availableData, options));
			if (IsRequired("ENCODED_ORDER", options.Version) || grpCCENCODED_ORDER_RSP_Z82) {
				return grpCCENCODED_ORDER_RSP_Z82;
			}
			bool isRXD = availableData.StartsWith("RXD", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("RXD", options.Version) || isRXD) {
				return isRXD;
			}
			bool isRXR = availableData.StartsWith("RXR", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("RXR", options.Version) || isRXR) {
				return isRXR;
			}
			bool isRXC = availableData.StartsWith("RXC", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("RXC", options.Version) || isRXC) {
				return isRXC;
			}
			OBSERVATION_RSP_Z82 testOBSERVATION_RSP_Z82 = new OBSERVATION_RSP_Z82();
			bool grpCCOBSERVATION_RSP_Z82 = (testOBSERVATION_RSP_Z82.CanConsume(availableData, options));
			if (IsRequired("OBSERVATION", options.Version) || grpCCOBSERVATION_RSP_Z82) {
				return grpCCOBSERVATION_RSP_Z82;
			}
			return false;
        }

        private static Dictionary<string, bool> SEGMENT_VERSION_REQUIRED_MAP = new Dictionary<string, bool>();

		protected override Dictionary<string, bool> MAP_OF_SEGMENT_TO_REQUIRED
        {
            get
			{
				return SEGMENT_VERSION_REQUIRED_MAP;
			}
        }

		public override string HL7ENTITY_TYPE_NAME
        {
            get {
				return "COMMON_ORDER";
			}
        }

        static COMMON_ORDER_RSP_Z82() {

             SetupStaticPropertyMap(SEGMENT_VERSION_REQUIRED_MAP, typeof(COMMON_ORDER_RSP_Z82));

        }

		#endregion

		public override string GetER7(HL7ParserOptions options)
		{
			List<string> segmentData = new List<string>();
		 if (ORC != null) {
			string segmentValue = ORC.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (ORDER_DETAIL != null) {
			string segmentValue = ORDER_DETAIL.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (ENCODED_ORDER != null) {
			string segmentValue = ENCODED_ORDER.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (RXD != null) {
			string segmentValue = RXD.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (RXR != null && RXR.Length > 0) {
			for (int i = 0; i < RXR.Length; i++) {
				string segmentValue = RXR[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
		 if (RXC != null && RXC.Length > 0) {
			for (int i = 0; i < RXC.Length; i++) {
				string segmentValue = RXC[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
		 if (OBSERVATION != null && OBSERVATION.Length > 0) {
			for (int i = 0; i < OBSERVATION.Length; i++) {
				string segmentValue = OBSERVATION[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
           return string.Join(HL7ParserConstants.SEGMENT_SEPARATOR, segmentData.ToArray());
        
        }
    }
}

